#include<iostream>

using namespace std;
struct ListNode {
	int val;
	struct ListNode *next;
	ListNode(int x) :
		val(x), next(NULL) {
	}
}; 
ListNode* ReverseList(ListNode* pHead) {
	if (!pHead)
		return nullptr;
	if (pHead->next == nullptr)
		return pHead;
	ListNode* cur = pHead;
	ListNode* next = pHead->next;
	while (cur->next)
	{
		ListNode* t = next->next;
		if (cur == pHead)
		{
			cur->next = nullptr;
			next->next = cur;
			cur = next;
			next = t;
		}
		else
		{
			next->next = cur;
			cur = next;
			next = t;
		}
		if (!next)
			pHead = cur;
	}
	return pHead;
}
int main()
{
	ListNode n1(1);
	ListNode n1(2);
	ListNode n1(3);
	ListNode n1(4);
	n1->next = n2;
	n2->next = n3;
	n3->next = n4;
	n4->next =nullptr;
	ListNode * pHead = n1;
	ReverseList(pHead);
}